package ustc.xiaoyang.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import ustc.xiaoyang.pojo.Clazz;
import ustc.xiaoyang.pojo.Result;
import ustc.xiaoyang.pojo.dto.ClazzPageQueryDTO;
import ustc.xiaoyang.service.ClazzService;

@RestController
@Slf4j
@RequestMapping("/clazzs")
public class ClazzController {
    private ClazzService clazzService;
    public ClazzController(ClazzService clazzService) {
        this.clazzService = clazzService;
    }
    @GetMapping
    public Result pageList(ClazzPageQueryDTO clazzPageQueryDTO){
        log.info("分页查询,查询参数：{}", clazzPageQueryDTO);
        return Result.success(clazzService.pageList(clazzPageQueryDTO));

    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        log.info("添加班级,班级信息：{}", clazz);
        clazzService.add(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询班级信息,id：{}", id);
        return Result.success(clazzService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息：{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除班级信息,id：{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        log.info("查询所有班级信息");
        return Result.success(clazzService.list());
    }

}
